<%-- 
    Document   : redi
    Created on : 14 Apr 11, 23:36:46
    Author     : Ismail Sunni
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="database.database" %>
<%@page import="java.util.ArrayList" %>
<%@page import="classes.User" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<script src="javascript/ajax_admin.js" type="text/javascript"></script>

<%
            String sUsername = request.getParameter("username");
            System.out.println("user " + sUsername);
            String sBanned = request.getParameter("ban");
            System.out.println("bans " + sBanned);
            String sPrivilege = request.getParameter("admin");
            System.out.println("privilege " + sPrivilege);
            database db = new database();
            db.connect();

            if (sBanned != null) {
                int nBanned = 0;
                if (sBanned.equals("0")) {
                    nBanned = 1;
                    System.out.println(nBanned);
                }

                if (sUsername != null && sUsername != "" && sBanned != null && sBanned != "") {
                    String strQuery = "UPDATE user SET banned = '" + nBanned + "' WHERE username = '" + sUsername + "'";
                    System.out.println(strQuery);
                    db.st = db._conn.createStatement();
                    int n = db.st.executeUpdate(strQuery);
                } else {
                }
            } else {

                if (sUsername != null && sUsername != "" && sPrivilege != null && sPrivilege != "") {
                    String strQuery = "UPDATE user SET privilege = '" + sPrivilege + "' WHERE username = '" + sUsername + "'";
                    System.out.println(strQuery);
                    db.st = db._conn.createStatement();
                    int n = db.st.executeUpdate(strQuery);
                } else {
                }
            }



%>
<%
            db = new database();
            ArrayList<User> arrayUser = db.getAllUser();
            if (!arrayUser.isEmpty()) {
                for (int i = 0; i < arrayUser.size(); ++i) {
                    out.println("<div class=\"oneuser\">");
                    out.println("<form action=\"\" >");
                    out.println(arrayUser.get(i).username);
                    if (arrayUser.get(i).banned) {
                        out.println("<input id=\"" + arrayUser.get(i).username + "#ban\" type=\"button\" class=\"tombol admintombol\" value=\"unBan\" OnClick=\"banUser('" + arrayUser.get(i).username + "#name');\"/>");
                    } else {
                        out.println("<input id=\"" + arrayUser.get(i).username + "#ban\"type=\"button\" class=\"tombol admintombol\" value=\"Ban\" OnClick=\"unBanUser('" + arrayUser.get(i).username + "#name');\"/>");
                    }
                    if (arrayUser.get(i).privilege.equals("moderator")) {
                        out.println("<input id=\"" + arrayUser.get(i).username + "#admin\" type=\"button\" class=\"tombol admintombol\" value=\"RemoveMomod\" OnClick=\" unMakeModerator('" + arrayUser.get(i).username + "#name');\"/>");
                    } else {
                        out.println("<input id=\"" + arrayUser.get(i).username + "#admin\" type=\"button\" class=\"tombol admintombol\" value=\"MakeMomod\" OnClick=\" makeModerator('" + arrayUser.get(i).username + "#name');\"/>");
                    }
                    out.println("</form>");
                    out.println("</div>");
                }
                out.println("<a href=\"redi.jsp?username=alpha&banned=ban\">TES</a>");
            } else {
                out.println("fail to load user...");
            }
%>